﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HYJHouseKeeping.Model;

namespace HYJHouseKeeping.DAL
{
    /// <summary>
    /// 考勤
    /// </summary>
    public class AttendanceService
    {
        #region
        /// <summary>
        /// 添加考勤记录（打上班卡）
        /// </summary>
        /// <returns></returns>
        public bool AddAttendance(Attendance attendance)
        {
            bool result = false;
            using (HYJHousekeepingEntities hyjhouse = new HYJHousekeepingEntities())
            {
                hyjhouse.Attendances.Add(new Attendance() 
                                                {
                                                    EmploeeID=attendance.EmploeeID,
                                                    StartTime=attendance.StartTime
                                                });
                if (hyjhouse.SaveChanges()>0)
                {
                    result = true;
                }
            }
            return result;
        }
        /// <summary>
        /// 签退
        /// </summary>
        /// <returns></returns>
        public bool UpdateAttendance(DateTime overTime,int employeeID,DateTime startTime)
        {
            bool result = false;
            using (HYJHousekeepingEntities hyjhouse = new HYJHousekeepingEntities())
            {
                Attendance att = hyjhouse.Attendances.FirstOrDefault(a=>a.StartTime==startTime);
                if (att!=null)
                {
                    att.OverTime = overTime;
                }
                if (hyjhouse.SaveChanges()>0)
                {
                    result = true;
                }
            }
            return result;
        }

        #endregion
    }
}
